﻿if(Tipel.Version == null) Tipel.Version = function(creater){
    var $ = this;
    
    var Vers = new Object();
    Vers[""] = "";
    Vers["cn"] = "";
    Vers["en"] = "en";
    
    function getVerPath(path, ver){
        if(path == null || path.length < 1) return "/"+ver;
        var i = path.indexOf("/", 0);
        if(i<0 || i>=path.length-1) return "/"+ver+path;
        var i1 = path.indexOf("/",i+1);
        if(i1< 0 || i1 <= i+1) return "/"+ver+path;
        var v = path.substr(i, i1-i-1);
        if(v == null || v.length< 1) return "/"+ver+path;
        v = v.Trim();
        if(v == null || v.length< 1) return "/"+ver+path;
        if(Vers[v] == undefined) return "/"+ver+path;
        path = path.substr(i1+1);
        return "/"+ver+path;
    };
    
    $.click = function(evt, node){
        node = $$.EvtNode(node, evt); 
        var ver = "";
        if(node == null || node.tpl == null) ver = "";
        else {
            var n = node.tpl.Attrs.Get("Ver");
            if(n == null) ver = "";
            ver = n.toLowerCase();
        }
        ver = Vers[ver];
        if(ver == null) ver = Vers[""];
        
        var path = getVerPath(location.pathname, ver);
        var search = location.search;
        var hash = location.hash;
        path += search+hash;
        
        ///alert(path);
    };
};
Tipel.Version.prototype = $$.Events;